package h0802;

import java.util.LinkedList;
import java.util.Scanner;

/**
 * @author 不知名帅哥
 * @version 1.0
 * @description 最大括号深度
 * @date 2024/8/2 23:49
 */
public class MaxBracketDepth {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.nextLine();
        LinkedList<Character> stack = new LinkedList<>();
        int res = getRes(stack, s);
        System.out.println(res);
    }

    private static int getRes(LinkedList<Character> stack, String s) {

        int maxDepth = 0;
        for (int i = 0; i < s.length(); i++) {
            char c = s.charAt(i);
            if (c == '(' || c == '[' || c == '{') {
                stack.addLast(c);
                //直接对比栈的深度就可以
                maxDepth = Math.max(stack.size(), maxDepth);
            } else if (!stack.isEmpty()) {
                if (c == ')' && stack.peekLast() == '('
                        || c == ']' && stack.peekLast() == '[' ||
                        c == '}' && stack.peekLast() == '{') {
                    stack.removeLast();
                } else return 0;
            } else {
                return 0;
            }
        }
        if (!stack.isEmpty()) {
            return 0;
        }
        return maxDepth;
    }
}
